package com.lhz.executor.impl;

import cn.hutool.core.util.StrUtil;
import com.lhz.executor.JobExecutor;
import com.lhz.log.JobLogRecord;
import com.lhz.model.entity.JobExecutorContext;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component;

import java.util.Map;
import java.util.Objects;
import java.util.concurrent.TimeUnit;

/**
 * @Author: LiHuaZhi
 * @Date: 2021/8/3 21:35
 * @Description:
 **/
@Component("systemExecutor")
@Slf4j
public class SystemExecutor implements JobExecutor {


    /**
     * 执行具体的业务
     *
     * @param context
     */
    @Override
    public void run(JobExecutorContext context) {
        Long jobId = context.getJobId();
        String jsonStr = context.getJsonStr();

        log.info("开始执行任务，任务Id：{}，任务参数：{}", jobId, jsonStr);
        String msg = "执行getSystem任务1=============";
        log.info(msg);
        JobLogRecord.success(jobId, msg);

        try {
            TimeUnit.SECONDS.sleep(1);
        } catch (InterruptedException e) {
            log.error(e.getMessage(), e);
        }

        msg = "执行getSystem任务2=============";
        log.info(msg);
        JobLogRecord.success(jobId, msg);
    }

    /**
     * 任务新增或者修改时的检查，默认直接返回true
     *
     * @param context
     * @return
     */
    @Override
    public boolean check(JobExecutorContext context) {
        return !Objects.isNull(context.getJobId());
    }
}
